<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文件列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script src="../../layuiadmin/layui/layui.js"></script>
<script src="../../jquery-3.4.1/jquery.min.js"></script>

<script>
    var localTest = layui.sessionData('test');
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'http://'+localTest.address+'/http/transfer/modifyList'
            ,cols: [[
                {field:'file_id', width:350, title: '文件ID'}
                ,{field:'owner', width:350, title: '文件拥有者'}
                ,{field:'price', width:100, title: '报价'}
                ,{field:'status', width:100, title: '状态',templet: '#titleTpl'}
                ,{width:150, align:'center', title: '操作',toolbar: '#barDemo'}
            ]]
            ,page: false
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'modify'){
                layer.open({
                    type: 2,
                    title: '修改交易',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['1400px', '500px'],
                    content:'../transfer/offer.html?fileID='+data.file_id,
                    cancel:function(index, layero){
                        window.location.reload();
                    }
                });
            }
            if(obj.event === 'cancel'){
                if(obj.event === 'cancel'){
                    layer.confirm('确认取消', function(index){
                        $.post("http://"+localTest.address+"/http/transfer/cancel",data,function(data,status){
                            window.location.reload();
                        });
                        layer.close(index);
                    });
                }
            }
        });

    });
</script>

<script type="text/html" id="titleTpl">
    {{#   if(d.status == 1){ }}
    <span style="color: #00FA9A;">已报价</span>
    {{#  } }}
</script>

<script type="text/html" id="barDemo">
    {{#  if(d.status == 1){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="modify">修改</a>
    {{#   } }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel">取消</a>
</script>

</body>
</html>